<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="排序号" prop="sortNo">
				<el-input-number v-model="form.sortNo" placeholder="排序号" clearable style="width: 100%"></el-input-number>
			</el-form-item>
			<el-form-item label="类型名称" prop="typeName">
				<el-input v-model="form.typeName" placeholder="类型名称" maxlength="80" clearable></el-input>
			</el-form-item>
			<el-form-item label="督查领导" prop="leadId">
				<select-user-dialog v-model:accountId="form.leadId" :mode="true"/>
			</el-form-item>
			<el-form-item label="BPM流程" prop="flowId">
				<el-select v-model="form.flowId" clearable style="width: 100%">
					<el-option v-for="item in flowOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="字段映射" prop="dataMap">
				<el-input v-model="form.dataMap" placeholder="字段映射" clearable type="textarea" maxlength="400" :show-word-limit="true"></el-input>
				<div class="el-form-item-msg">如 field1:d_xxx1,field2:d_xxx2,格式为"数据表字段:流程表字段"</div>
			</el-form-item>
			<el-form-item label="备注说明" prop="remark">
				<el-input v-model="form.remark" placeholder="备注说明" clearable type="textarea" maxlength="380"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	emits: ['success', 'closed'],
	components: {
		selectUserDialog
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			titleMap: {
				add: '添加督查类型',
				edit: '编辑督查类型',
				show: '查看'
			},
			fileList: [],
			flowOptions:[],
			form: {
				configId: '',
				typeName: "",
				dataMap:'',
				sortNo: 0,
				leadId: "",
				flowId: '',
				remark: '',
			},
			rules: {
				sortNo: [
					{required: true, message: '排序号不能为空', trigger: 'blur'}
				],
				typeName: [
					{required: true, message: '类型名称不能为空', trigger: 'blur'}
				],
				leadId: [
					{required: true, message: '督查领导不能为空', trigger: 'blur'}
				],
				/*dataMap: [
					{required: true, message: '映射字段不能为空', trigger: 'blur'}
				],*/
			}
		}
	},
	mounted() {
		this.getBpmFlowListForSelect();
	},
	methods: {
		async getBpmFlowListForSelect()
		{
			var res = await this.$API.bpm.bpmFlow.getBpmFlowListForSelect.get({model:'0'});
			if(res.code == 200){
				this.flowOptions = res.data;
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.supervision.supervisionConfig.insertSupervisionConfig.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.supervision.supervisionConfig.updateSupervisionConfig.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.configId = data.configId
			this.form.typeName = data.typeName
			this.form.dataMap = data.dataMap
			this.form.sortNo = data.sortNo
			this.form.leadId = data.leadId
			this.form.flowId = data.flowId
			this.form.remark = data.remark
		},
	}
}
</script>

<style>
</style>
